import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import Components from 'unplugin-vue-components/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig({
  base: "./",
  plugins: [vue(),
    Components({
      resolvers: [NaiveUiResolver()],//使用自定义组件库
    }),
  ],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  define: {
    "process.env.csm": `'${process.env.VITE_CSM_API}'`,//需要npm教本设置命令动态修改环境变量set VITE_CSM_API=CSM2 && vite
  },
  server: {
    host: "0.0.0.0",
    port: 3000,
    open: true,
  },
  build: {
    rollupOptions: {
      output: {
        chunkFileNames: "js/[name]-[hash].js", // 引入文件名的名称
        entryFileNames: "js/[name]-[hash].js", // 包的入口文件名称
        assetFileNames: "[ext]/[name]-[hash].[ext]", // 资源文件像 字体，图片等
      },
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/assets/style/comm.scss";',
      },
    },
  },
});
